<template>
  <div class="app-container">
    <!-- 查询模块 -->
    <div class="formDiv">
      <el-form ref="form"  :inline="true" :model="form" label-width="130px">
        <el-row>
          <el-col :span="6">
            <el-form-item label="公司全称">
              <el-input v-model="form.branchOfficeName" placeholder="请输入公司全称" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="公司简称">
              <el-input v-model="form.branchOfficeNick" placeholder="请选公司简称" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item>
              <el-button type="primary" @click="searchFn()">查询</el-button>
              <el-button type="primary" @click="toRoutes('paymentAdd')">添加</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- 主页列表 -->
    <div v-loading="tableLoading" class="listDiv">
      <!-- table列表 -->
      <el-table :data="tableData" style="width: 100%">
        <el-table-column fixed type="index" label="序列" />
        <el-table-column prop="branchOfficeName" label="缴款公司" />
        <el-table-column prop="branchOfficeNick" label="公司简称" />
        <el-table-column prop="branchOfficeType" label="公司类型" />
        <el-table-column prop="paymentType" label="缴款类型" />
        <el-table-column prop="amount" label="本次缴费" />
        <el-table-column prop="totalAmount" label="截止本次累计缴款" />
        <el-table-column prop="time" label="缴款时间" />
        <el-table-column prop="remark" label="备注" />
      </el-table>
      <!-- 分页 -->
      <div class="pagesCon">
        <div>
          <el-pagination
            :current-page="listForm.pageNum"
            :page-sizes="page_sizes"
            :page-size="listForm.limit"
            layout="total, sizes, prev, pager, next, jumper"
            :total="page_totals"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { getList, addPayment } from '@/api/paymentDetails'
export default {
  name: 'PaymentDetails',
  filters: {},
  data() {
    return {
      tableLoading: true,
      dates: [],
      form: {
        branchOfficeName: '',
        branchOfficeNick: '',
        managerName: '',
        managerPhone: '',
        pageNum: 1,
        pageSize: 10
      },
      tableData: [],
      page_sizes: [10, 30, 50, 100],
      page_totals: 60,
      listForm: {
        pageNum: 1,
        pageSize: 10
      }
    }
  },
  mounted() {
    // console.log(this.$route.query.id)
    this.form.branchOfficeName = this.$route.query.id
    this.getList(this.form)
  },
  methods: {
    // 按钮权限
    hasPermission(e) {
      return window.helper.hasPermission(e)
    },
    // 成功状态弹窗
    succStatus(txt) {
      this.$message({
        message: txt + '成功',
        type: 'success'
      })
    },
    // 失败状态弹窗
    errorStatus(txt) {
      this.$message.error(txt + '失败')
    },
    // 路由跳转
    toRoutes(e, id) {
      const route = { name: e, query: { id: id }}
      this.$router.push(route)
    },
    // 列表数据获取
    getList(e) {
      this.tableLoading = true
      const datas = e
      getList(datas)
        .then(res => {
          // console.log(res)
          if (!res.data.code) {
            // console.log(res)
            this.tableData = res.data.data.list
            this.page_totals = res.data.data.count
          } else {
            this.$message.error(res.data.msg)
          }
          this.tableLoading = false
        })
        .catch(error => {
          this.$message.error(error)
        })
    },
    // 查询
    searchFn() {
      this.form.pageNum = 1
      if (this.dates != null) {
        if (this.dates.length) {
          this.form.createdAtStart = this.dates[0]
          this.form.createdAtEnd = this.dates[1]
          this.getList(this.form)
        } else {
          this.getList(this.form)
        }
      } else {
        this.form.createdAtStart = ''
        this.form.createdAtEnd = ''
        this.getList(this.form)
      }
      // console.log(JSON.stringify(this.form))
    },
    // 改变页面条数
    handleSizeChange(val) {
      this.form.pageSize = val
      this.getList(this.form)
    },
    // 选择页数
    handleCurrentChange(val) {
      this.form.pageNum = val
      this.getList(this.form)
    },
    // 删除
    deleteList(e) {
      const datas = { id: e }
      this.$confirm('删除该条数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          filialeFOIndexListDelete(datas).then(res => {
            if (!res.data.code) {
              this.succStatus('删除')
              this.getList(this.form)
            } else {
              this.$message.error(res.data.msg)
            }
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    }
  }
}
</script>
<style scoped>
/* 分页 */
.pagesCon {
  height: 40px;
  margin-top: 20px;
}
.pagesCon > div {
  float: right;
}
/* 表单样式修改 */
.el-range-editor--medium.el-input__inner {
  width: 236px;
}
</style>
